package com.miraksoft.statewatcher.bean;

import java.util.ArrayList;
import java.util.List;

import android.widget.Chronometer;

public class WatchedObjectRuntimeContainer {

	private List<WatchedObjectRuntime> objectRuntimes = new ArrayList<WatchedObjectRuntime>();

	public void add(WatchedObjectRuntime watchedObjectRuntime){
		objectRuntimes.add(watchedObjectRuntime);
	}
	
	public String serialize(){
		return null;
	}
	
	public static void deserialize( String serializedContainer ){
		
	}
	
	public WatchedObjectRuntime addWatchedObjecRuntime(WatchedObjectDef watchedObject){

		WatchedObjectRuntime watchedObjectRuntime = new WatchedObjectRuntime( watchedObject );
		objectRuntimes.add(watchedObjectRuntime);
		
		return watchedObjectRuntime;
		
	}
	
	public WatchedObjectStateRuntime getRuntimeStateByButtonId( Integer btnId ){
		
		for( WatchedObjectRuntime objectRuntime : objectRuntimes) {
		
			WatchedObjectStateRuntime objectStateRuntime = objectRuntime.getRuntimeStateByButtonId( btnId );
			if( objectStateRuntime != null){
				return objectStateRuntime;
			}
		}
		
		return null;
	}

	
	public List<WatchedObjectStateRuntime> getAllWatchedObjectStateRuntimes(){
		
		ArrayList<WatchedObjectStateRuntime> objectStateRuntimes = new ArrayList<WatchedObjectStateRuntime>();
		
		for ( WatchedObjectRuntime objectRuntime : objectRuntimes) {
			for ( WatchedObjectStateRuntime stateRuntime : objectRuntime.getStateRuntimes()) {
				
				objectStateRuntimes.add(stateRuntime);
				
			}
		}
		
		return objectStateRuntimes;
	}

	public List<WatchedObjectStateRuntime> getRunningWatchedObjectStateRuntimes(){
		
		ArrayList<WatchedObjectStateRuntime> objectStateRuntimes = new ArrayList<WatchedObjectStateRuntime>();
		
		for ( WatchedObjectRuntime objectRuntime : objectRuntimes) {
			WatchedObjectStateRuntime runningStateRuntime = objectRuntime.getRunningStateRuntime();
				
			if( runningStateRuntime != null ){
				objectStateRuntimes.add( runningStateRuntime );
			}
				
		}
		
		return objectStateRuntimes;
	}

	public List<WatchedObjectStateRuntime> getPausedWatchedObjectStateRuntimes(){
		
		ArrayList<WatchedObjectStateRuntime> objectStateRuntimes = new ArrayList<WatchedObjectStateRuntime>();
		
		for ( WatchedObjectRuntime objectRuntime : objectRuntimes) {
			for ( WatchedObjectStateRuntime stateRuntime : objectRuntime.getStateRuntimes()) {
				
				if( stateRuntime.isPaused()){
					objectStateRuntimes.add(stateRuntime);
				}
				
			}
		}
		
		return objectStateRuntimes;
	}

	public List<WatchedObjectStateRuntime> getDefaultWatchedObjectStateRuntimes(){
		
		ArrayList<WatchedObjectStateRuntime> objectStateRuntimes = new ArrayList<WatchedObjectStateRuntime>();
		
		for ( WatchedObjectRuntime objectRuntime : objectRuntimes) {
			for ( WatchedObjectStateRuntime stateRuntime : objectRuntime.getStateRuntimes()) {
				if( stateRuntime.isDefault() ){
				
					objectStateRuntimes.add(stateRuntime);
					
				}
			}
		}
		
		return objectStateRuntimes;
	}

}
